const router = require("koa-router")();
import { ReadFile, WriteFile } from "../utils/ReadWriteFile";

// 处理接收前端请求的路由
router.post("/api/update-array", async (ctx) => {
  try {
    const { newArray } = ctx.request.body;
    // 从指定的文件中读取数组
    // let result = await ReadFile('userReportData');
    // 修改数组
    // result = newArray;
    // 将修改后的数组写入文件
    await WriteFile({ type: "userReportData", result: newArray });

    ctx.body = {
      code: 200,
      message: "数组更新成功",
    };
  } catch (error) {
    ctx.status = 500;
    ctx.body = {
      code: 500,
      message: "服务器内部错误，数组更新失败",
    };
  }
});